using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using WorkflowApplicationsData = ScenarioFramework.WorkflowEngine.DataModel.WorkflowApplicationsData;

namespace Scenario.Modeler
{
	/// <summary>
	/// Descrizione di riepilogo per Applications.
	/// </summary>
	public class Applications : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.ListView listApplications;
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.Button btnAdd;
		private System.Windows.Forms.Button btnModify;
		private System.Windows.Forms.Button btnDelete;
		/// <summary>
		/// Variabile di progettazione necessaria.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Applications()
		{
			//
			// Necessario per il supporto di Progettazione Windows Form
			//
			InitializeComponent();

			//
			// TODO: aggiungere il codice del costruttore dopo la chiamata a InitializeComponent
			//
		}

		/// <summary>
		/// Pulire le risorse in uso.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Codice generato da Progettazione Windows Form
		/// <summary>
		/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
		/// il contenuto del metodo con l'editor di codice.
		/// </summary>
		private void InitializeComponent()
		{
            this.listApplications = new System.Windows.Forms.ListView();
            this.panel1 = new System.Windows.Forms.Panel();
            this.btnClose = new System.Windows.Forms.Button();
            this.btnModify = new System.Windows.Forms.Button();
            this.btnAdd = new System.Windows.Forms.Button();
            this.btnDelete = new System.Windows.Forms.Button();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // listApplications
            // 
            this.listApplications.Location = new System.Drawing.Point(7, 14);
            this.listApplications.Name = "listApplications";
            this.listApplications.Size = new System.Drawing.Size(860, 541);
            this.listApplications.TabIndex = 0;
            this.listApplications.UseCompatibleStateImageBehavior = false;
            this.listApplications.View = System.Windows.Forms.View.Details;
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.btnClose);
            this.panel1.Controls.Add(this.btnModify);
            this.panel1.Controls.Add(this.btnAdd);
            this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.panel1.Location = new System.Drawing.Point(0, 659);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(1048, 56);
            this.panel1.TabIndex = 1;
            // 
            // btnClose
            // 
            this.btnClose.Location = new System.Drawing.Point(540, 14);
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new System.Drawing.Size(120, 28);
            this.btnClose.TabIndex = 3;
            this.btnClose.Text = "Close";
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // btnModify
            // 
            this.btnModify.Location = new System.Drawing.Point(333, 14);
            this.btnModify.Name = "btnModify";
            this.btnModify.Size = new System.Drawing.Size(140, 28);
            this.btnModify.TabIndex = 1;
            this.btnModify.Text = "Modify";
            // 
            // btnAdd
            // 
            this.btnAdd.Location = new System.Drawing.Point(113, 14);
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new System.Drawing.Size(127, 28);
            this.btnAdd.TabIndex = 0;
            this.btnAdd.Text = "Add";
            // 
            // btnDelete
            // 
            this.btnDelete.Location = new System.Drawing.Point(0, 0);
            this.btnDelete.Name = "btnDelete";
            this.btnDelete.Size = new System.Drawing.Size(75, 23);
            this.btnDelete.TabIndex = 0;
            // 
            // Applications
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(1048, 715);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.listApplications);
            this.Name = "Applications";
            this.Text = "Applications";
            this.Load += new System.EventHandler(this.Applications_Load);
            this.panel1.ResumeLayout(false);
            this.ResumeLayout(false);

		}
		#endregion

		private void Applications_Load(object sender, System.EventArgs e)
		{
			listApplications.Clear();
			listApplications.Columns.Add("Name",listApplications.Width - 400, HorizontalAlignment.Left);
			listApplications.Columns.Add("Type",200, HorizontalAlignment.Left);
			listApplications.Columns.Add("Library",200, HorizontalAlignment.Left);

            ScenarioFramework.WAPI.Response response = new ScenarioFramework.WAPI.Response();

            string sApplications = ScenarioFramework.WAPI.Application.GetApplications(ref response);
			WorkflowApplicationsData.XMLApplications vApplications = new WorkflowApplicationsData.XMLApplications();

			vApplications.Parse (sApplications);

			if ( response.iCode == 0 )
			{
				for ( int i=0; i<vApplications.Count; i++)
				{
					WorkflowApplicationsData.XMLApplication application = (WorkflowApplicationsData.XMLApplication) vApplications[i];
					ListViewItem item =null;
					item = new ListViewItem( new string[] { application.Name, application.Type, application.LibraryFile });

					listApplications.Items.Add ( item);
				}
			}
		}

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}
